﻿
namespace SistemaLogistica.DataAccess
{
    using System.Collections.Generic;
    using System.Data;
    using System.Data.Common;
    using SistemaLogistica.Business.Entities;

    public class DetalleGuiaRemisionData : BaseDataAccess
    {
        private DetalleGuiaRemisionData() { }

        private static readonly DetalleGuiaRemisionData instancia = new DetalleGuiaRemisionData();

        public static DetalleGuiaRemisionData Instancia
        {
            get { return instancia; }
        }

        public List<DetalleGuiaRemision> ListarPorGuiaRemision(int guiaRemisionID)
        {
            List<DetalleGuiaRemision> detalleGuiaRemision = new List<DetalleGuiaRemision>();
            DbCommand command = db.GetStoredProcCommand("GetDetalleGuiaRemisionByGuiaRemisionID");
            db.AddInParameter(command, "idGuiaRemision", DbType.Int32, guiaRemisionID);

            using (IDataReader dr = db.ExecuteReader(command))
            {
                while (dr.Read())
                {
                    detalleGuiaRemision.Add(new DetalleGuiaRemision
                    {
                        Bien = BienData.Instancia.ObtenerPorID(dr.GetInt32(dr.GetOrdinal("IdBien"))),
                        Cantidad = dr.GetDecimal(dr.GetOrdinal("Cantidad")),
                        Precio = dr.GetDecimal(dr.GetOrdinal("Precio")),
                        IdGuiaRemision = dr.GetInt32(dr.GetOrdinal("IdGuiaRemision"))
                    });
                }
            }
            return detalleGuiaRemision;
        }
    }
}
